🎖️GitЯра🎖️
src/Identity.h 890a2e2cffa98dea3ca88db3c3aba72ef23ff3f7 (890a2e2c) Text, 3.38 KB
Tff7b72#Tff7b72pragma once
Tff7b72#Tff7b72include T8b949e<Utils.h>
Tff7b72#Tff7b72include T8b949e<Stream.h>
Te6edf3namespace Te6edf3mesh Tb4b4b4{
T8b949e/**
* \brief An identity in the mesh, with given Ed25519 public key, ie. a party whose signatures can be VERIFIED.
*/
Te6edf3class Te6edf3Identity Tb4b4b4{
Te6edf3publicTff7b72:
Tffa657uint8_t Te6edf3pub_keyTb4b4b4[Te6edf3PUB_KEY_SIZETb4b4b4]Tb4b4b4;
Te6edf3IdentityTb4b4b4(Tb4b4b4)Tb4b4b4;
Te6edf3IdentityTb4b4b4(Tff7b72const Tffa657charTff7b72* Te6edf3pub_hexTb4b4b4)Tb4b4b4;
Te6edf3IdentityTb4b4b4(Tff7b72const Tffa657uint8_tTff7b72* Te6edf3_pubTb4b4b4) Tb4b4b4{ Te6edf3memcpyTb4b4b4(Te6edf3pub_keyTb4b4b4, Te6edf3_pubTb4b4b4, Te6edf3PUB_KEY_SIZETb4b4b4)Tb4b4b4; Tb4b4b4}
Tffa657int Te6edf3copyHashToTb4b4b4(Tffa657uint8_tTff7b72* Te6edf3destTb4b4b4) Tff7b72const Tb4b4b4{
Te6edf3memcpyTb4b4b4(Te6edf3destTb4b4b4, Te6edf3pub_keyTb4b4b4, Te6edf3PATH_HASH_SIZETb4b4b4)Tb4b4b4; T8b949e// hash is just prefix of pub_key
Tff7b72return Te6edf3PATH_HASH_SIZETb4b4b4;
Tb4b4b4}
Tffa657int Te6edf3copyHashToTb4b4b4(Tffa657uint8_tTff7b72* Te6edf3destTb4b4b4, Tffa657uint8_t Te6edf3lenTb4b4b4) Tff7b72const Tb4b4b4{
Te6edf3memcpyTb4b4b4(Te6edf3destTb4b4b4, Te6edf3pub_keyTb4b4b4, Te6edf3lenTb4b4b4)Tb4b4b4; T8b949e// hash is just prefix of pub_key
Tff7b72return Te6edf3lenTb4b4b4;
Tb4b4b4}
Tffa657bool Te6edf3isHashMatchTb4b4b4(Tff7b72const Tffa657uint8_tTff7b72* Te6edf3hashTb4b4b4) Tff7b72const Tb4b4b4{
Tff7b72return Te6edf3memcmpTb4b4b4(Te6edf3hashTb4b4b4, Te6edf3pub_keyTb4b4b4, Te6edf3PATH_HASH_SIZETb4b4b4) Tff7b72=Tff7b72= T79c0ff0Tb4b4b4;
Tb4b4b4}
Tffa657bool Te6edf3isHashMatchTb4b4b4(Tff7b72const Tffa657uint8_tTff7b72* Te6edf3hashTb4b4b4, Tffa657uint8_t Te6edf3lenTb4b4b4) Tff7b72const Tb4b4b4{
Tff7b72return Te6edf3memcmpTb4b4b4(Te6edf3hashTb4b4b4, Te6edf3pub_keyTb4b4b4, Te6edf3lenTb4b4b4) Tff7b72=Tff7b72= T79c0ff0Tb4b4b4;
Tb4b4b4}
T8b949e/**
* \brief Performs Ed25519 signature verification.
* \param sig IN - must be SIGNATURE_SIZE buffer.
* \param message IN - the original message which was signed.
* \param msg_len IN - the length in bytes of message.
* \returns true, if signature is valid.
*/
Tffa657bool Te6edf3verifyTb4b4b4(Tff7b72const Tffa657uint8_tTff7b72* Te6edf3sigTb4b4b4, Tff7b72const Tffa657uint8_tTff7b72* Te6edf3messageTb4b4b4, Tffa657int Te6edf3msg_lenTb4b4b4) Tff7b72constTb4b4b4;
Tffa657bool Td2a8ffmatchesTb4b4b4(Tff7b72const Te6edf3IdentityTff7b72& Te6edf3otherTb4b4b4) Tff7b72const Tb4b4b4{ Tff7b72return Te6edf3memcmpTb4b4b4(Te6edf3pub_keyTb4b4b4, Te6edf3otherTb4b4b4.Te6edf3pub_keyTb4b4b4, Te6edf3PUB_KEY_SIZETb4b4b4) Tff7b72=Tff7b72= T79c0ff0Tb4b4b4; Tb4b4b4}
Tffa657bool Td2a8ffmatchesTb4b4b4(Tff7b72const Tffa657uint8_tTff7b72* Te6edf3other_pubkeyTb4b4b4) Tff7b72const Tb4b4b4{ Tff7b72return Te6edf3memcmpTb4b4b4(Te6edf3pub_keyTb4b4b4, Te6edf3other_pubkeyTb4b4b4, Te6edf3PUB_KEY_SIZETb4b4b4) Tff7b72=Tff7b72= T79c0ff0Tb4b4b4; Tb4b4b4}
Tffa657bool Td2a8ffreadFromTb4b4b4(Te6edf3StreamTff7b72& Te6edf3sTb4b4b4)Tb4b4b4;
Tffa657bool Td2a8ffwriteToTb4b4b4(Te6edf3StreamTff7b72& Te6edf3sTb4b4b4) Tff7b72constTb4b4b4;
Tffa657void Td2a8ffprintToTb4b4b4(Te6edf3StreamTff7b72& Te6edf3sTb4b4b4) Tff7b72constTb4b4b4;
Tb4b4b4}Tb4b4b4;
T8b949e/**
* \brief An Identity generated on THIS device, ie. with public/private Ed25519 key pair being on this device.
*/
Te6edf3class Te6edf3LocalIdentity Tff7b72: Te6edf3public Te6edf3Identity Tb4b4b4{
Tffa657uint8_t Te6edf3prv_keyTb4b4b4[Te6edf3PRV_KEY_SIZETb4b4b4]Tb4b4b4;
Te6edf3publicTff7b72:
Te6edf3LocalIdentityTb4b4b4(Tb4b4b4)Tb4b4b4;
Te6edf3LocalIdentityTb4b4b4(Tff7b72const Tffa657charTff7b72* Te6edf3prv_hexTb4b4b4, Tff7b72const Tffa657charTff7b72* Te6edf3pub_hexTb4b4b4)Tb4b4b4;
Te6edf3LocalIdentityTb4b4b4(Te6edf3RNGTff7b72* Te6edf3rngTb4b4b4)Tb4b4b4; T8b949e// create new random
T8b949e/**
* \brief Ed25519 digital signature.
* \param sig OUT - must be SIGNATURE_SIZE buffer.
* \param message IN - the raw message bytes to sign.
* \param msg_len IN - the length in bytes of message.
*/
Tffa657void Td2a8ffsignTb4b4b4(Tffa657uint8_tTff7b72* Te6edf3sigTb4b4b4, Tff7b72const Tffa657uint8_tTff7b72* Te6edf3messageTb4b4b4, Tffa657int Te6edf3msg_lenTb4b4b4) Tff7b72constTb4b4b4;
T8b949e/**
* \brief the ECDH key exhange, with Ed25519 public key transposed to Ex25519.
* \param secret OUT - the 'shared secret' (must be PUB_KEY_SIZE bytes)
* \param other IN - the second party in the exchange.
*/
Tffa657void Td2a8ffcalcSharedSecretTb4b4b4(Tffa657uint8_tTff7b72* Te6edf3secretTb4b4b4, Tff7b72const Te6edf3IdentityTff7b72& Te6edf3otherTb4b4b4) Tff7b72const Tb4b4b4{ Te6edf3calcSharedSecretTb4b4b4(Te6edf3secretTb4b4b4, Te6edf3otherTb4b4b4.Te6edf3pub_keyTb4b4b4)Tb4b4b4; Tb4b4b4}
T8b949e/**
* \brief the ECDH key exhange, with Ed25519 public key transposed to Ex25519.
* \param secret OUT - the 'shared secret' (must be PUB_KEY_SIZE bytes)
* \param other_pub_key IN - the public key of second party in the exchange (must be PUB_KEY_SIZE bytes)
*/
Tffa657void Td2a8ffcalcSharedSecretTb4b4b4(Tffa657uint8_tTff7b72* Te6edf3secretTb4b4b4, Tff7b72const Tffa657uint8_tTff7b72* Te6edf3other_pub_keyTb4b4b4) Tff7b72constTb4b4b4;
T8b949e/**
* \brief Validates that a given private key can be used for ECDH / shared-secret operations.
* \param prv IN - the private key to validate (must be PRV_KEY_SIZE bytes)
* \returns true, if the private key is valid for login.
*/
Tff7b72static Tffa657bool Td2a8ffvalidatePrivateKeyTb4b4b4(Tff7b72const Tffa657uint8_t Te6edf3prvTb4b4b4[T79c0ff64Tb4b4b4]Tb4b4b4)Tb4b4b4;
Tffa657bool Td2a8ffreadFromTb4b4b4(Te6edf3StreamTff7b72& Te6edf3sTb4b4b4)Tb4b4b4;
Tffa657bool Td2a8ffwriteToTb4b4b4(Te6edf3StreamTff7b72& Te6edf3sTb4b4b4) Tff7b72constTb4b4b4;
Tffa657void Td2a8ffprintToTb4b4b4(Te6edf3StreamTff7b72& Te6edf3sTb4b4b4) Tff7b72constTb4b4b4;
Tffa657size_t Td2a8ffwriteToTb4b4b4(Tffa657uint8_tTff7b72* Te6edf3destTb4b4b4, Tffa657size_t Te6edf3max_lenTb4b4b4)Tb4b4b4;
Tffa657void Td2a8ffreadFromTb4b4b4(Tff7b72const Tffa657uint8_tTff7b72* Te6edf3srcTb4b4b4, Tffa657size_t Te6edf3lenTb4b4b4)Tb4b4b4;
Tb4b4b4}Tb4b4b4;
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.06s